今天開始來帶大家串接綠界B2C電子發票規格
首先提幾個「串接前」要了解的事情:
這樣才能在「正式環境」使用綠界電子發票服務
接下來,在「開立發票前」有三大步驟要執行:
https://developers.ecpay.com.tw/?p=7859
「正式環境」:
先確認授權到綠界的字軌編號有哪些
「測試環境」:
綠界測試環境有提供模擬的字軌編號,可以先行串接此API,查看會拿到哪些資料
實際在測試環境呼叫API
{"MerchantID":"2000132","InvoiceYear":"113"}
可以取回如下資訊
{"RtnCode":1,"RtnMsg":"成功","InvoiceInfo":[{"InvoiceTerm":1,"InvType":"07","InvoiceHeader":"MA","InvoiceStart":"70000000","InvoiceEnd":"70000099","Number":2},{"InvoiceTerm":2,"InvType":"07","InvoiceHeader":"NQ","InvoiceStart":"80000000","InvoiceEnd":"80000099","Number":2},{"InvoiceTerm":3,"InvType":"07","InvoiceHeader":"PG","InvoiceStart":"90000000","InvoiceEnd":"90000099","Number":2},{"InvoiceTerm":4,"InvType":"07","InvoiceHeader":"QV","InvoiceStart":"70000000","InvoiceEnd":"70002499","Number":50},{"InvoiceTerm":5,"InvType":"07","InvoiceHeader":"SK","InvoiceStart":"80000000","InvoiceEnd":"80002499","Number":50},{"InvoiceTerm":6,"InvType":"07","InvoiceHeader":"TZ","InvoiceStart":"90000000","InvoiceEnd":"90002499","Number":50}]}
array(3) { ["RtnCode"]=> int(1) ["RtnMsg"]=> string(6) "成功" ["InvoiceInfo"]=> array(6) { [0]=> array(6) { ["InvoiceTerm"]=> int(1) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "MA" ["InvoiceStart"]=> string(8) "70000000" ["InvoiceEnd"]=> string(8) "70000099" ["Number"]=> int(2) } [1]=> array(6) { ["InvoiceTerm"]=> int(2) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "NQ" ["InvoiceStart"]=> string(8) "80000000" ["InvoiceEnd"]=> string(8) "80000099" ["Number"]=> int(2) } [2]=> array(6) { ["InvoiceTerm"]=> int(3) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "PG" ["InvoiceStart"]=> string(8) "90000000" ["InvoiceEnd"]=> string(8) "90000099" ["Number"]=> int(2) } [3]=> array(6) { ["InvoiceTerm"]=> int(4) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "QV" ["InvoiceStart"]=> string(8) "70000000" ["InvoiceEnd"]=> string(8) "70002499" ["Number"]=> int(50) } [4]=> array(6) { ["InvoiceTerm"]=> int(5) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "SK" ["InvoiceStart"]=> string(8) "80000000" ["InvoiceEnd"]=> string(8) "80002499" ["Number"]=> int(50) } [5]=> array(6) { ["InvoiceTerm"]=> int(6) ["InvType"]=> string(2) "07" ["InvoiceHeader"]=> string(2) "TZ" ["InvoiceStart"]=> string(8) "90000000" ["InvoiceEnd"]=> string(8) "90002499" ["Number"]=> int(50) } } }
以上,就是有授權給綠界使用的所有配號字軌
https://developers.ecpay.com.tw/?p=7870
查到有哪些字軌配號後
接下來就是要分別進行設定
字軌配號是每兩個月為一期:
一、二月為第一期
三、四月為第二期
以此類推
電子發票號碼是「每50碼」為一組
且起始數字一定是00或50,而結尾數字一定是49或99
例如FA10000000-FA10000049就是一組
FA就是字軌
10000000就是配號
每一期都要設定字軌與配號
綠界才會知道要用哪個字軌配號開立發票哦
例如
此文章撰寫的時間為9月
那就必須將發票期別(InvoiceTerm)設定為5(9-10月)
起始發票編號(InvoiceStart)設為TH80002350
結束發票編號(InvoiceEnd)設為TH80002399
{"MerchantID":"2000132","InvoiceTerm":"5","InvoiceYear":"113","InvType":"07","InvoiceCategory":"1","InvoiceHeader":"TH","InvoiceStart":"80002350","InvoiceEnd":"80002399"}
設定成功後,綠界會回傳一組TrackID
{"RtnCode":1,"RtnMsg":"成功","TrackID":"4067"}
array(3) { ["RtnCode"]=> int(1) ["RtnMsg"]=> string(6) "成功" ["TrackID"]=> string(4) "4067" }
從綠界後台也能找到這組字軌
剛設定完的字軌編號
使用狀態會是「未啟用」
後面就是用這組TrackID操作字軌啟用狀態
https://developers.ecpay.com.tw/?p=7875
第二步驟設定完字軌配號後
記得要將字軌配號設定為「啟用」
使用剛剛取得的TrackID來進行啟用
{"MerchantID":"2000132","TrackID":"4067","InvoiceStatus":"2"}
啟用完成後,會收到如下回覆
{"RtnCode":1,"RtnMsg":"成功"}
array(2) { ["RtnCode"]=> int(1) ["RtnMsg"]=> string(6) "成功" }
綠界後台也可以看到使用狀態已經變為「啟用中」
後續呼叫開立發票時
綠界就會從TH80002350開始「順時順序」開立發票
這樣就算完成開立發票的前置囉
以上就是在開立發票前必須要做的前置動作
但其實這些前置作業完全可以在綠界後台手動操作
而且向財政部申請字軌配號通常都是會計在執行
因此這些前置作業可以直接讓會計去綠界後台操作即可
不串API也是可以的哦
就看自己怎麼規劃囉
我們明天見